#include <iostream>
#include <string>
#include <functional>

using std::cout;
using std::endl;
using std::string;
using std::function;

int gNum = 100;

void test0()
{
    int num = 10;
    int age = 33;
    string name("lili");
    auto f = [num, &age, name](int value){
        ++value;
        cout << "value = " << value << endl;
        cout << "num = " << num << endl;
        ++age;
        cout << "age = " << age << endl;
        cout << "name = " << name << endl;
        ++gNum;
        cout << "gNum = " << gNum << endl;
    };

    f(100);
    cout << endl << endl;
    f(100);

}

void test()
{
    int num = 10;
    int age = 33;
    string name("lili");
    /* void (*f)(int);//error */
    function<void(int)> f = [num, &age, name](int value)->void{
        ++value;
        cout << "value = " << value << endl;
        cout << "num = " << num << endl;
        ++age;
        cout << "age = " << age << endl;
        cout << "name = " << name << endl;
        ++gNum;
        cout << "gNum = " << gNum << endl;
    };

    f(300);
    cout << endl << endl;
    f(300);

}
int main(int argc, char *argv[])
{
    test();
    return 0;
}

